const ValidationDataUtil = {};
//数据类型 1数字，2文字，3日期，4图片，5附件，6员工，7项目，8项目计划
//时间转换到本地的天

ValidationDataUtil.validationData = function(value,modelInfo) {
  let formData = value.data;
  let rules = modelInfo.widgets;
  let fieldConfigList = modelInfo.fieldConfigList
  let error = []
  console.log(rules);
  if(rules&&rules.length){
	  for(let i = 0; i < formData.length; i++){
		  console.log(rules[i]);
		  if(rules[i]&&rules[i].notnull&&(formData[i].value==null || (formData[i].value&&formData[i].value.length==0))){ //是否必填
			  error.push(fieldConfigList[i].fieldName + '不能为空')
		  }else if(rules[i]&&rules[i].type&&formData[i].value){ //容器类型,不必填但是有值
			  switch(rules[i].type){
					  case "input": //输入框
					  if(rules[i].config.input_type== 'number'){ //数字类型
						  if(!isNumber(formData[i].value)){
							 error.push(fieldConfigList[i].fieldName + '只能填写数字')
						  }else if(rules[i].config.max&&Number(formData[i].value) > Number(rules[i].config.max)){
							 error.push(fieldConfigList[i].fieldName + '填写的最大值为' + rules[i].config.max)
						  }else if(rules[i].config.min&&Number(formData[i].value) < Number(rules[i].config.min)){
							 error.push(fieldConfigList[i].fieldName + '填写的最小值为' + rules[i].config.min)
						  }
					  }else if(rules[i].config.input_type == 'text'){ //文本类型
						  if(formData[i].value && formData[i].value.length> 30 ){
							error.push(fieldConfigList[i].fieldName + '长度不能超过30字')
						  }
					  }
					  break;
					  case "text_area": //文本域
						  if(rules[i].config.maxlength&&formData[i].value.length > Number(rules[i].config.maxlength)){ //字数最大限制
							  error.push(fieldConfigList[i].fieldName + '最大字数为' + rules[i].config.maxlength)
						  }
					  break;
					  case "date_select": //时间类型，数值字符串转为时间对象
					  value.data[i].value = new Date(value.data[i].value)
					  break;
					  case "file": //文件
					  break;
					  case "process_strip": //进度条
					  break;
					  case "user_select": //人员选择
					  break;
					  case "image": //图片
					  break;
					  case "project_select"://项目选择
					  break;
			  }
		  }
	  }
  }
  return {error,value};
};

function  isNumber (checkVal){
	let reg = /^-?[1-9][0-9]?.?[0-9]*$/;
	return reg.test(checkVal);
}

export default ValidationDataUtil;
